package com.hc.sss.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hc.sss.common.ResultMap;
import com.hc.sss.mapper.UserMapper;
import com.hc.sss.pojo.Dict;
import com.hc.sss.pojo.User;
import com.hc.sss.service.UserService;

/**
 * userconservator[用户会员表]service
 *
 */

@Service
public class UserServiceImpl implements UserService {
	
	@Autowired
	UserMapper usermapper;

	//会员登录
	@Override
	public User login(User user) {
		return usermapper.login(user);
	}

	//会员注册
	@Override
	public int addUser(User user) {
		if(usermapper.userFindByName(user)!=null) {
			return 0;
		}
		usermapper.addUser(user);
		return 1;
	}

	//修改信息
	@Override
	public int updateByPrimaryKeySelective(User record) {
		return usermapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public User userFindByName(User user) {
		return usermapper.userFindByName(user);
	}

	//查询所有用户分页   llz  04/10 9:56
	public ResultMap<User> findUserList(Map<String, Object> paramMap) {
		ResultMap<User> resultMap = new ResultMap<User>();
		Integer page = 1;
		Integer limit = 5;
		if (paramMap.get("page") != null && !"".equals(paramMap.get("page"))) {
			page = Integer.valueOf(paramMap.get("page").toString());
		}
		if (paramMap.get("limit") != null && !"".equals(paramMap.get("limit"))) {
			limit = Integer.valueOf(paramMap.get("limit").toString());
		}
		PageHelper.startPage(page, limit);
		List<User> list = usermapper.findUserList(paramMap);
		PageInfo<User> info = new PageInfo<>(list);
		resultMap.setData(list);
		resultMap.setCount((int)info.getTotal());
		return resultMap;
	}

	//查询所有用户
	@Override
	public List<User> selectUserAll() {
		return usermapper.selectUserAll();
	}

}
